﻿<presentation:MetroView
    x:Name="PageRoot"
    x:Class="OnYourWayHome.ShoppingListView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:presentation="using:OnYourWayHome.ApplicationModel.Presentation"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    NavigationCacheMode="Required"
    mc:Ignorable="d">

    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Command="{Binding GoBackCommand}" Style="{StaticResource BackButtonStyle}"/>
            <TextBlock x:Name="pageTitle" Grid.Column="1" Text="shopping list" Style="{StaticResource PageHeaderTextStyle}"/>
        </Grid>

        <!-- Horizontal scrolling grid used in most view states -->
        <ScrollViewer
            Grid.Row="2"
            Style="{StaticResource VerticalScrollViewerStyle}">

            <ItemsControl 
                Margin="120,0,120,0"
                ItemsSource="{Binding GroceryItems}" 
                HorizontalAlignment="Left">
                
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        
                            <Grid Width="440">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="350"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                
                                <CheckBox Grid.Column="0"
                                          Margin="0,-13,0,-13"
                                          Content="{Binding Name}" 
                                          IsChecked="{Binding IsInCart}" 
                                          Command="{Binding DataContext.ChangeIsInCartCommand, ElementName=PageRoot}" 
                                          CommandParameter="{Binding}" />

                              <Button Grid.Column="1"
                                      Width="45"
                                      Height="45"
                                      BorderThickness="0"
                                      Command="{Binding DataContext.RemoveItemCommand, ElementName=PageRoot}"
                                      CommandParameter="{Binding}">
                                  <Image Source="/Assets/appbar.delete.rest.png" />
                              </Button>
                              
                              
                             </Grid>

                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </ScrollViewer>

      <StackPanel Grid.Row="2" Orientation="Horizontal" Margin="120,0,120,60">
        <Button Command="{Binding NavigateToAddGroceryItemCommand}"
                Content="add..." />

        <Button Command="{Binding CheckoutCommand}"
                Content="check out" />
      </StackPanel>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup>
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!--
                    The back button and title have different styles when snapped, and the list representation is substituted
                    for the grid displayed in all other view states
                -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/>
                        </ObjectAnimationUsingKeyFrames>
        
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
    
    <Page.BottomAppBar>
        <AppBar Padding="10,0,10,0">
            <Button Command="{Binding GoHomeCommand}"  HorizontalAlignment="Left" Style="{StaticResource HomeAppBarButtonStyle}"/>
        </AppBar>
    </Page.BottomAppBar>
    
</presentation:MetroView>
